﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WebSocketChatServer
{
    /// <summary>
    /// 请求
    /// </summary>
    public class RequestMsg
    {
        private string? requestId;
        /// <summary>
        /// 动作编码
        /// </summary>
        private int serviceId;
        private string? name;
        private string? message;

        public string RequestId { get => requestId!; set => requestId = value; }
        public int ServiceId { get => serviceId; set => serviceId = value; }
        public string Name { get => name!; set => name = value; }
        public string Message { get => message!; set => message = value; }

        // JSON格式发送
        public string ToJson()
        {
            return JsonConvert.SerializeObject(this);
        }

        public override string ToString()
        {
            return ToJson();
        }

        public static RequestMsg? createInstance(string json)
        {
            if (!string.IsNullOrWhiteSpace(json))
                return JsonConvert.DeserializeObject<RequestMsg>(json);

            return null;
        }
    }
}
